<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="180px"
    >

      <el-form-item label="机构名称" prop="orgName">
        <el-input
          v-model="queryParams.orgName"
          placeholder=""
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同编号" prop="contractId">
        <el-input
          v-model="queryParams.contractId"
          placeholder="请输入合同编号"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="机构类型" prop="orgTypeCd">
        <el-select
          v-model="queryParams.orgTypeCd"
          placeholder="机构类型"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="item in orgTypeCdList"
            :key="item.dictValue"
            :value="item.dictValue"
            :label="item.dictLabel"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="分供类型" prop="offerType">
        <el-select
          v-model="queryParams.offerType"
          placeholder="分供类型"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="item in offerTypeList"
            :key="item.dictValue"
            :value="item.dictValue"
            :label="item.dictLabel"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-button
        type="primary"
        plain
        icon="el-icon-plus"
        size="mini"
        @click="handleAdd"
      >新增
      </el-button>
    </el-row>

    <el-table v-loading="loading" :data="tableData">
      <el-table-column width="350" label="机构简称" align="center" prop="orgShortName"/>
      <el-table-column width="100" label="机构类型" align="center" prop="orgTypeCdText"/>
      <el-table-column width="80" label="负责人" align="center" prop="leaderName"/>
      <el-table-column width="110" label="联系电话" align="center" prop="orgTelNum"/>
      <el-table-column width="100" label="信用金额" align="center" prop="creditAmount"/>
      <el-table-column width="100" label="订单授信" align="center" prop="orderCredit">
        <template slot-scope="scope">
          <span style="color: #00afff"
                class="goDetail"
                @click="orderCredit(scope.row)"
          >
                  {{ scope.row.orderCredit}}
                </span>
        </template>
      </el-table-column>
      <el-table-column width="100" label="未付金额" align="center" prop="notPay"/>
      <el-table-column width="100" label="管理费比例" align="center" prop="feeCent"/>
      <el-table-column width="120" label="分供类型" align="center" prop="offerTypeText"/>
      <el-table-column width="100" label="门市类型" align="center" prop="saleTypeText"/>
<!--      <el-table-column width="100" label="可用短信条数" align="center" prop="smsCountNum"/>-->
      <el-table-column width="160" label="修改日期" align="center" prop="setDt"/>
      <el-table-column width="110" label="开始日期" align="center" prop="beginDt"/>
      <el-table-column width="110" label="结束日期" align="center" prop="closeDt"/>
      <el-table-column width="80" label="审核标志" align="center" prop="activeInd">
        <template slot-scope="scope">
          {{ scope.row.activeInd == 1 ? '已审核' : '未审核' }}
        </template>
      </el-table-column>
<!--      <el-table-column label="checkIndex名称" align="center" prop="checkIndex"/>
      <el-table-column label="ciden名称" align="center" prop="ciden">
        <template slot-scope="scope">
          {{ scope.row.ciden == 0 ? '隐藏' : '显示' }}
        </template>
      </el-table-column>-->

      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">

          <el-button
            size="mini"
            type="text"
            icon="el-icon-document"
            @click="handleDetail(scope.row)"
          >详情
          </el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click=""
          >下级机构
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handAmount(scope.row)"
          >修改授信金额
          </el-button>

<!--          <el-button
            size="mini"
            type="text"
            v-if="scope.row.activeInd!=3"
            icon="el-icon-document"
            @click=""
          >短信充值
          </el-button>-->
<!--          <el-button
            size="mini"
            type="text"
            v-if="scope.row.activeInd==3"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除
          </el-button>-->

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <Create ref="createDialog"/>
    <Detail ref="detailDialog"/>
    <Updateamount ref="updateamountDialog" @confirm="getList"/>
    <Creditindex ref="creditindexDialog" @confirm="getList"/>
  </div>
</template>

<script>
import {pageList, deleteById} from "@/api/system/organization"
import Create from "@/views/system/org/create";
import Detail from "@/views/system/org/detail";
import Updateamount from "@/views/system/org/updateamount";
import Creditindex from "@/views/saleorder/creditindex";
import {getDictData} from "@/api/system/dict/data";

export default {
  name: "organization",
  components: {Create, Detail,Updateamount,Creditindex},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      tableData: [],
      orgTypeCdList:[],
      offerTypeList:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orgName: "",
        orgTypeCd: "",
        offerType: "",
      },
    }
  },
  created() {
    this.getList()
    this.getOptions();
  },
  methods: {
    /** 查询合同列表 */
    getList() {
      this.loading = true
      pageList(this.queryParams).then(response => {
          this.tableData = response.rows
          this.total = response.total
          this.loading = false
        }
      )
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.createDialog.open()
    },
    /** 查看详情操作 */
    handleDetail(row) {
      this.$refs.detailDialog.open(row.orgId)
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.createDialog.open(row.orgId)
    },
    handAmount(row) {
      this.$refs.updateamountDialog.open(row.orgId)
    },
    orderCredit(row) {
      this.$refs.creditindexDialog.open(row.orgId)
    },
    getOptions() {
      getDictData('orgTypeCd').then(res => {
        this.orgTypeCdList = res.data
      })
      getDictData('offerType').then(res => {
        this.offerTypeList = res.data
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal.confirm('是否确认删除？').then(function () {
        return deleteById(row.id)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {
      })
    },
  }
}
</script>
